package Controller;

/**
 * @author: tangBin
 * @Date: 2022/1/6 0006 10:08
 * @Description: 模拟银行自助叫号机
 */
public class TicketWindowExample implements Runnable {

    private int index = 1;
    private final static int max = 100;
    private final static Object MUTEX = new Object();

    @Override
    public void run() {
        synchronized (MUTEX) {
            while (index <= max) {
                System.out.println(Thread.currentThread() + "的号码是：" + (index++));
            }
            ;
        }
    }

    public static void main(String[] args) {
        TicketWindowExample task = new TicketWindowExample();
        Thread window1 = new Thread(task, "一号窗口");
        Thread window2 = new Thread(task, "二号窗口");
        Thread window3 = new Thread(task, "三号窗口");
        window1.start();
        window2.start();
        window3.start();
    }
}
